package cn.doourbest.learnspring.validator;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.Collection;

public class NotEmptyBlankValidator implements ConstraintValidator<NotEmptyBlank, Collection> {

    @Override
    public boolean isValid(Collection collection, ConstraintValidatorContext context) {
        if ( collection == null ) {
            return false;
        }

        int size = collection.size();
        if(size <= 0){
            return false;
        }

        int num = (int) collection.stream().filter(x -> x.toString().trim().length() <= 0).count();
        return num <= 0;

    }
}
